

apiready = function(){
	
	
	
	var total='';
	var id = api.pageParam.shopId;
	getPastLottery(id,true)
	
	function getPastLottery(id,isReload,currentPage) {
    var pageSize = 10;
    currentPage=isReload?0:currentPage;

    api.ajax({
        url: 'http://wap.jqmao.cn/getPastLottery',
        method: 'post',
        data: {
            values: {id: id, pageSize: pageSize,currentPage:currentPage}
        }
    }, function (ret, err) {

        if (ret) {
        	
            total = ret['total']
            var content = $api.byId('pastLottery-content');
            var tpl = $api.byId('pastLottery-template').text;
            var tempFn = doT.template(tpl);
            //alert($api.getStorage('type'));
            //alert(type)
            api.hideProgress();

            if (isReload) {
                 $api.setStorage("currentPage", 0);        // 重新设置为0
                $api.html(content, tempFn(ret['listItems']));
                
            } else {
                $api.append(content, tempFn(ret['listItems']));
            }


        } else {
           //alert(JSON.stringify(err))
        }
        
    });
    

}


 //下拉刷新

   api.setCustomRefreshHeaderInfo({
    bgColor: '#fff',
    isScale: true,
    image: {
        pull: 'widget://image/refresh/1.png', 
        transform: [
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png',
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png',
            'widget://image/refresh/6.png',
            'widget://image/refresh/7.png'
        ],
        load: [ 
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png', 
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png'
        ]
    }
}, function() {
  if(api.connectionType!='none'){
  	
  	
	        //alert(typeName)	      
            //下拉刷新被触发，自动进入加载状态，使用 api.refreshHeaderLoadDone() 手动结束加载中状态
            var typeName = $api.getStorage('type');
       getPastLottery(id,true)
     
       

            setTimeout(function(){  
            api.refreshHeaderLoadDone();               
	    }, 800);
  }else{
  	 setTimeout(function(){          
  	 		toast("没有网络，请检查网络设置")          
	        api.refreshHeaderLoadDone();
	    }, 800);
  }
  
  
        
           
      });
//上拉加载
    api.addEventListener({

        name: 'scrolltobottom',
        extra: {
            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
        }
    }, function (ret, err) {
        $("#more").show();
        
        var _page=parseInt($api.getStorage("currentPage"));
        if(_page+10<=total){

         getPastLottery(id,false,_page+10);
        $api.setStorage("currentPage", _page+10); // 页码+1
        }else{
            $("#more").hide();
        }
      
       
    });
    
}
